package com.magtonic.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class Check_TextView extends View {
	TextView mTextView;
	String mStr;
	//
	public Check_TextView(Context context) {
		super(context);
		initCheck_TextView();
	}

	public Check_TextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initCheck_TextView();
	}

	public Check_TextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initCheck_TextView();
	}
	
	private void initCheck_TextView(){
		mTextView = new TextView(getContext());
		mTextView.setText("title");	
	}
	
	public void setText(String str){
		mStr = str;
		
		this.requestLayout();
		this.invalidate();
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		switch(event.getAction()){
			case MotionEvent.ACTION_DOWN:
				this.setBackgroundColor(Color.WHITE);
				break;
			case MotionEvent.ACTION_UP:
				this.setBackgroundColor(Color.BLACK);
				break;
		}
		
		this.invalidate();
		return true;//super.onTouchEvent(event);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec)); 
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		//super.onDraw(canvas);
		mTextView.setText(mStr);
	}	
}
